if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[sp_GetArticlesByScripture]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[sp_GetArticlesByScripture]
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE sp_GetArticlesByScripture 
/*
	Mult-purpose Article Search Capability	
	Version 0.6
	Coded By Zhang Xiaohua
	30/6/06
*/
(
	@Title		nvarchar(50),
	@Chapter	smallint,
	@Section	smallint,
	@Chapter_to	smallint,
	@Section_to 	smallint
)
 AS

	SELECT * FROM v_articles 
	 WHERE NOT ApproveUserID IS NULL AND Type='post' AND (BibleTitle=@Title
	   	AND NOT ((@Chapter_to=BibleChapter AND @Section_to<BibleSection) 
		    OR (@Chapter_to<BibleChapter))
	   	AND NOT ((@Chapter=BibleChapter_To AND @Section>BibleSection_To) 
		    OR (@Chapter>BibleChapter_To)))
	   OR NOT ApproveUserID IS NULL AND Type='post' AND (PostID IN (SELECT PostID FROM PostBible WHERE BibleTitle=@Title
	   	AND NOT ((@Chapter_to=BibleChapter AND @Section_to<BibleSection) 
		    OR (@Chapter_to<BibleChapter))
	   	AND NOT ((@Chapter=BibleChapter_To AND @Section>BibleSection_To) 
		    OR (@Chapter>BibleChapter_To))))
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

